home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Games of Daze
/
Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso
/
x2ftp
/
msdos
/
math
/
nrpas13
/
polcoe.dem
< prev
next >
Wrap
Text File
|
1991-04-29
|
2KB
|
64 lines
PROGRAM d3r7 (input,output);
(* driver for routine POLCOE *)
LABEL 1;
CONST
np=5;
pi=3.1415926;
TYPE
glnarray = ARRAY [1..np] OF real;
VAR
i,j,nfunc : integer;
f,sum,x : real;
coeff,xa,ya : glnarray;
(*$I MODFILE.PAS *)
(*$I POLCOE.PAS *)
BEGIN
FOR nfunc := 1 to 2 DO BEGIN
IF (nfunc = 1) THEN BEGIN
writeln ('sine function from 0 to pi');
writeln;
FOR i := 1 to np DO BEGIN
xa[i] := i*pi/np;
ya[i] := sin(xa[i])
END
END ELSE IF (nfunc = 2) THEN BEGIN
writeln ('exponential function from 0 to 1');
writeln;
FOR i := 1 to np DO BEGIN
xa[i] := 1.0*i/np;
ya[i] := exp(xa[i])
END
END ELSE BEGIN
GOTO 1
END;
polcoe(xa,ya,np,coeff);
writeln (' ':2,'coefficients');
FOR i := 1 to np DO BEGIN
writeln (coeff[i]:12:6)
END;
writeln;
writeln('x':9,'f(x)':13,'polynomial':15);
FOR i := 1 to 10 DO BEGIN
IF (nfunc = 1) THEN BEGIN
x := (-0.05+i/10.0)*pi;
f := sin(x)
END ELSE IF (nfunc = 2) THEN BEGIN
x := -0.05+i/10.0;
f := exp(x)
END;
sum := coeff[np];
FOR j := np-1 DOWNTO 1 DO BEGIN
sum := coeff[j]+sum*x
END;
writeln (x:12:6,f:12:6,sum:12:6)
END;
writeln;
writeln ('************************************');
writeln ('press RETURN');
readln
END;
1:
END.